<?
/**
 * Copyright 2007 Melange.
 *
 * This file is part of PHP-MELANGE.
 *
 * PHP-MELANGE is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * PHP-MELANGE is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with PHP-MELANGE; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * @category    Melange
 * @package     php-melange
 * @subpackage  cms
 * @copyright   Copyright (c) 2007 Jeroen Simons. All rights reserved
 * @author      Jeroen Simons <jeroen@melange.nl>
 * @link        http://www.melange.nl/
 *
 */
?>
<?=$this->header()?>


    <?=$this->menu("menus")?>


    <h1><?=$this->message("label.item.header", _Menu::BUNDLE)?></h1>


    <? /* Breadcrums route */ ?>
    <?=$this->route(
        array_merge(
            array(array(
                "name"=>$this->message("label.header", _Menu::BUNDLE),
                "href"=>"menu/list"
            )),
            $this->menuRoute($this->itemForm->getItemI18n()->getMenuItem()->getParentId()),
            array(array(
                "name"=>$this->message("label.item.header", _Menu::BUNDLE) . " " .
                    $this->message("title.for", _Core::BUNDLE) . " " .
                        strtolower($this->message("label.item".
                            ($this->itemForm->getItemI18n()->getMenuItem()->getParentId() == 0 ? "" :
                            ".item"), _Menu::BUNDLE)) . " " .
                                " \"" . ($this->itemForm->getItemI18n()->getMenuItem()->getParentId() == 0 ?
                                    $this->itemForm->getItemI18n()->getMenuItem()->getMenu()->getName() :
                                    $this->itemForm->getItemI18n()->getMenuItem()->getMenuItemRelatedByParentId()->getDefaultName(
                                        $this->itemForm->getItemI18n()->getMenuItem()->getMenu()->getLanguageCode()
                                    )."\""),
                "href"=>"menu/item/list"
            )),
            array(array(
                "name"=>$this->languageRoute(
                            $this->message("label.item.item", _Menu::BUNDLE),                                        // Item name
                            $this->itemForm->getItemI18n()->getDefaultName(
                                $this->itemForm->getItemI18n()->getMenuItem()->getMenu()->getLanguageCode()), // Default language item name
                            $this->itemForm->getItemI18n()->getMenuItemI18nId(),                                    // Id
                            $this->itemForm->getItemI18n()->getLanguage(),                                       // Language
                            $this->itemForm->getItemI18n()->getMenuItem()->getMenu()->getLanguageCode())      // Overwrite default language
            ))
        )
    )?>


    <? /* Show error messages */ ?>
    <?=$this->errors(null, _Menu::BUNDLE)?>


    <form id="<?=get_class($this->itemForm)?>"
          action="menu/item/save"
          method="post"
          class="uniForm">

        <div>
            <input type="hidden" 
                   name="itemI18n->menuItem->menuId"
                   value="<?=$this->itemForm->getItemI18n()->getMenuItem()->getMenuId()?>" />
            <input type="hidden"
                   name="itemI18n->menuItem->parentId"
                   value="<?=$this->itemForm->getItemI18n()->getMenuItem()->getParentId()?>" />
            <input type="hidden"
                   name="itemI18n->menuItemId"
                   value="<?=$this->itemForm->getItemI18n()->getMenuItemId()?>" />
            <input type="hidden"
                   name="itemI18n->menuItemI18nId"
                   value="<?=$this->itemForm->getItemI18n()->getMenuItemI18nId()?>" />
            <input type="hidden"
                   name="itemI18n->languageCode"
                   value="<?=$this->itemForm->getItemI18n()->getLanguageCode()?>" />
        </div>

        <? if($this->itemForm->getItemI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>
            <p><?=$this->message("note.main", _Menu::BUNDLE, null, null, false)?></p>
        <? endif; ?>

        <fieldset>

            <legend><?=$this->message("label.required", _Core::BUNDLE)?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("itemI18n->name")?>">
                <th><label for="itemI18n_name"><?=$this->message("prompt.item.name", _Menu::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="itemI18n->name"
                           id="itemI18n_name"
                           value="<?=$this->itemForm->getItemI18n()->getName()?>"
                           maxlength="30"
                           type="text"
                           class="textInput" />
                </td>
            </tr>

            <? /* Only show link field with default language pages */ ?>
            <? if($this->itemForm->getItemI18n()->getLanguageCode() == $this->param(_Core::DEFAULT_LANGUAGE)): ?>
            <tr class="ctrl<?=$this->error("itemI18n->menuItem->link")?>">
                <th><label for="itemI18n_menuItem_link"><?=$this->message("prompt.item.link", _Menu::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <input name="itemI18n->menuItem->link"
                           id="itemI18n_menuItem_link"
                           value="<?=$this->itemForm->getItemI18n()->getMenuItem()->getLink()?>"
                           maxlength="30"
                           type="text"
                           class="textInput" />
                    <p class="hint"><?=$this->message("note.url", _Core::BUNDLE)?></p>
                </td>
            </tr>
            <tr class="ctrl">
                <th></th>
                <th></th>
                <td><?=$this->message("label.or", _Core::BUNDLE)?></td>
            </tr>
            <tr class="ctrl<?=$this->error("internalLink")?>">
                <th><label for="internalLink"><?=$this->message("prompt.item.link.internal", _Menu::BUNDLE)?></label></th>
                <th class="required"><em>*</em></th>
                <td>
                    <?=$this->menuitemLinks()->modules()?>
                    <br />
                    <?=$this->menuitemLinks()->links()?>
                </td>
            </tr>
            <? endif; ?>

            </table>

        </fieldset>


        <fieldset>

            <legend><?=$this->message("label.optional")?></legend>

            <table cellspacing="0" cellpadding="0" class="form">
            <tr class="ctrl<?=$this->error("formImage")?>">
                <th><label for="formImage"><?=$this->message("label.image", _Core::BUNDLE)?></label></th>
                <th class="required"><em>&nbsp;</em></th>
                <td>
                    <? if(!is_null($this->staffForm->getStaff()) &&
                        $this->staffForm->getStaff()->getImageId() > 0 &&
                        !is_null($this->staffForm->getStaff()->getImageRelatedByImageId())) { ?>

                        <input type="hidden"
                               name="staff->imageRelatedByImageId->imageId"
                               value="<?=$this->staffForm->getStaff()->getImageId()?>" />
                        <input type="hidden"
                               name="staff->imageRelatedByThumbnailId->imageId"
                               value="<?=$this->staffForm->getStaff()->getThumbnailId()?>" />

                        <input type="hidden"
                               name="staff->imageRelatedByImageId->binaryFileId"
                               value="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getBinaryFileId()?>" />
                        <input type="hidden"
                               name="staff->imageRelatedByThumbnailId->binaryFileId"
                               value="<?=$this->staffForm->getStaff()->getImageRelatedByThumbnailId()->getBinaryFileId()?>" />

                        <img src="image?id=<?=$this->staffForm->getStaff()->getImageId()?>"
                             width="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getWidth()?>"
                             height="<?=$this->staffForm->getStaff()->getImageRelatedByImageId()->getHeight()?>" alt="" />

                        <input type="checkbox" name="deleteImage" value="true" id="deleteImage" /> <label for="deleteImage"><?=$this->message("label.image.delete", _Core::BUNDLE)?></label>

                        <br /><br />

                    <? } ?>

                    <input type="file" name="formImage" />

                    <p class="hint"><?=$this->message("note.image.resize", _Core::BUNDLE)?> <?=$this->imageProps($this->param(_Core::SETTING_LIST))->getImageWidth()?>x<?=$this->imageProps($this->param(_CORE::SETTING_LIST))->getImageHeight()?>.</p>

                </td>
            </tr>
            </table>

        </fieldset>

        <div class="buttons">

            <input type="button"
                   onclick="to('menu/item/list')"
                   value="<?=$this->message("button.cancel", _Core::BUNDLE)?>"
                   class="button" />
            <input type="submit"
                   name="save"
                   value="<?=$this->message("button.submit", _Core::BUNDLE)?>"
                   class="button" />

        </div>

    </form>

<?=$this->footer()?>